package com.clock.mapper;


import com.clock.domain.entity.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * (Tag)表数据库访问层
 *
 * @author makejava
 * @since 2022-12-29 21:24:01
 */
@Mapper
public interface TagMapper {

    /*查询所有标签,慎用*/
    @Select("select * from tag")
    List<Tag> queryAll ();

    @Select("select * from tag where tag_id = #{tagId}}")
    Tag queryByTagId(Integer tagId);

    @Select("select * from tag where tag_content = #{tagContent}")
    Tag queryByTagContent(String tagContent);

    /*根据模块找标签*/
    @Select("select  * from tag where tag_module_id = #{moduleId}")
    List<Tag> queryAllByTagModuleIdTags(@Param("moduleId") Integer moduleId);

    int insert(Tag tag);

    int deleteById(Tag tag);

    List<Tag> queryTagsById(@Param("tagIds") Integer[] tagIds);

    @Delete("delete from tag where tag_module_id = #{moduleId} and tag_content = #{tagContent}")
    int delByTagContentAndTagModuleIdInt(@Param("moduleId") Integer moduleID,@Param("tagContent") String tagContent);

    @Select("SELECT tag_content FROM tag\tWHERE tag_id = (SELECT tag_id FROM post_related_tag WHERE post_id in (\n" +
            "SELECT post_id FROM discuss_post WHERE user_id = #{userId}\n" +
            "and MONTH(create_time) = MONTH(now()) and YEAR(create_time) = YEAR(now()))\t \n" +
            "GROUP BY tag_id ORDER BY COUNT(1) DESC LIMIT 0,1)")
    String queryOneTagNameByPostLike(Long userId);
}
